package com.gogowan.agroenterprise.widget.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.gogowan.agroenterprise.R;
import com.gogowan.agroenterprise.model.ChanPinDiatalBean;
import com.gogowan.agroenterprise.model.ChuKuDiatalBean;
import com.gogowan.agroenterprise.utils.INewAdapterClick;
import com.gogowan.agroenterprise.utils.Utils;
import com.google.zxing.common.StringUtils;

import java.util.List;

public class ChuKuDiatalAdapter extends BaseAdapter {

	private final INewAdapterClick click;
	private Context context;
	private List<ChuKuDiatalBean> datas;

	public ChuKuDiatalAdapter(Context context, List<ChuKuDiatalBean> datas, INewAdapterClick click) {
		this.context = context;
		this.datas = datas;
		this.click=click;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return datas.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return datas.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder;
		if (convertView == null) {
			convertView = LayoutInflater.from(context).inflate(R.layout.chuku_detail_item, null);
			viewHolder = new ViewHolder();
			viewHolder.ll_main =  convertView.findViewById(R.id.ll_main);
			viewHolder.tv_no = (TextView) convertView.findViewById(R.id.tv_no);
			viewHolder.tv_time = (TextView) convertView.findViewById(R.id.tv_time);
			viewHolder.tv_chanpin_number = (TextView) convertView.findViewById(R.id.tv_chanpin_number);
			viewHolder.tv_0_number = (TextView) convertView.findViewById(R.id.tv_0_number);
			viewHolder.tv_1_number = (TextView) convertView.findViewById(R.id.tv_1_number);
			viewHolder.tv_2_number = (TextView) convertView.findViewById(R.id.tv_2_number);
			viewHolder.tv_chuku_fang = (TextView) convertView.findViewById(R.id.tv_chuku_fang);
			viewHolder.tv_jieshou_fang = (TextView) convertView.findViewById(R.id.tv_jieshou_fang);
			viewHolder.tv_beizhu = (TextView) convertView.findViewById(R.id.tv_beizhu);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		ChuKuDiatalBean chuKuDiatalBean = datas.get(position);
		String quantitySpec = chuKuDiatalBean.getQuantitySpec();
		Integer[] numbers = Utils.getNumbers(quantitySpec);
		viewHolder.tv_no.setText(chuKuDiatalBean.getNumber());
		viewHolder.tv_time.setText(chuKuDiatalBean.getOutboundTime());
		viewHolder.tv_chanpin_number.setText(numbers[1]+numbers[3]+numbers[5]+"");
		viewHolder.tv_0_number.setText(chuKuDiatalBean.getQuantity());
		viewHolder.tv_1_number.setText(numbers[3]+"");
		viewHolder.tv_2_number.setText(numbers[5]+"");
		viewHolder.tv_chuku_fang.setText(chuKuDiatalBean.getCreateBy());
		viewHolder.tv_jieshou_fang.setText(chuKuDiatalBean.getInputor());
		viewHolder.tv_beizhu.setText(chuKuDiatalBean.getRemark());
		viewHolder.ll_main.setOnClickListener(view -> {
			click.onItemClick(view,position);
		});
		return convertView;
	}

	static class ViewHolder {
		public TextView tv_no;
		public View ll_main;
		public TextView tv_time,tv_chuku_fang,tv_0_number,tv_1_number,tv_2_number,tv_chanpin_number,tv_jieshou_fang,tv_beizhu;
	}

}
